/*
 *ER/Studio 7.0 SQL Code Generation
 * Company :      ygeR@ZWT
 * Project :      Model1.DM1
 * Author :       Lorry
 *
 * Date Created : Tuesday, May 01, 2012 21:47:12
 * Target DBMS : Microsoft SQL Server 2005
 */

/* 
 * TABLE: LastPlans 
 */

CREATE TABLE LastPlans(
    ID            int         NOT NULL,
    CreateDate    datetime    NOT NULL,
    PlanID        int         NULL,
    CONSTRAINT PK1_1 PRIMARY KEY NONCLUSTERED (ID)
)
go



IF OBJECT_ID('LastPlans') IS NOT NULL
    PRINT '<<< CREATED TABLE LastPlans >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE LastPlans >>>'
go

/* 
 * TABLE: Plan 
 */

CREATE TABLE PlanInfo(
    ID            int              IDENTITY(1,1),
    UserID        int              NULL,
    PlanName      nvarchar(100)    NULL,
    CreateDate    datetime         NULL,
    CONSTRAINT PK9 PRIMARY KEY NONCLUSTERED (ID)
)
go



IF OBJECT_ID('Plan') IS NOT NULL
    PRINT '<<< CREATED TABLE Plan >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Plan >>>'
go

/* 
 * TABLE: PlanItem 
 */

CREATE TABLE PlanItem(
    ID                  int               IDENTITY(1,1),
    Date                datetime          NOT NULL,
    StartTime           datetime          NULL,
    EndTime             datetime          NULL,
    AllowUseComputer    bit               NULL,
    Context             nvarchar(1000)    NULL,
    CreateOn            datetime          NULL,
    UpdateOn            datetime          NULL,
    CONSTRAINT PK5 PRIMARY KEY NONCLUSTERED (ID)
)
go



IF OBJECT_ID('PlanItem') IS NOT NULL
    PRINT '<<< CREATED TABLE PlanItem >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE PlanItem >>>'
go

/* 
 * TABLE: Template 
 */

CREATE TABLE Template(
    ID            int              IDENTITY(1,1),
    UserID        int              NULL,
    PlanName      nvarchar(100)    NULL,
    CreateDate    datetime         NULL,
    CONSTRAINT PK9_1 PRIMARY KEY NONCLUSTERED (ID)
)
go



IF OBJECT_ID('Template') IS NOT NULL
    PRINT '<<< CREATED TABLE Template >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Template >>>'
go

/* 
 * TABLE: TemplateItem 
 */

CREATE TABLE TemplateItem(
    ID                  int               NOT NULL,
    StartTime           datetime          NULL,
    EndTime             datetime          NULL,
    AllowUseComputer    bit               NULL,
    Context             nvarchar(1000)    NULL,
    CreateOn            datetime          NULL,
    UpdateOn            char(10)          NULL,
    CONSTRAINT PK1_2 PRIMARY KEY NONCLUSTERED (ID)
)
go



IF OBJECT_ID('TemplateItem') IS NOT NULL
    PRINT '<<< CREATED TABLE TemplateItem >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE TemplateItem >>>'
go

/* 
 * TABLE: User 
 */

CREATE TABLE User(
    ID          int              IDENTITY(1,1),
    UserName    nvarchar(100)    NULL,
    Password    char(18)         NULL,
    CONSTRAINT PK8 PRIMARY KEY NONCLUSTERED (ID)
)
go



IF OBJECT_ID('User') IS NOT NULL
    PRINT '<<< CREATED TABLE User >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE User >>>'
go

CREATE TABLE LastTemplates(
    ID            int         NOT NULL,
    CreateDate    datetime    NOT NULL,
    TempID        int         NULL,
    CONSTRAINT PK1_1_1 PRIMARY KEY NONCLUSTERED (ID)
)
go

